import {ArgumentMetadata, BadRequestException, Inject, Injectable, PipeTransform} from '../../index'
import {ParseFileOptions} from "./file-validator";

@Injectable()
export class ParseFilePipe implements PipeTransform {
    constructor(private options:ParseFileOptions={}) {

    }
    async transform(value: any, metadata: ArgumentMetadata) {
        if(!value){
            throw new BadRequestException('no file submitted')
        }
        if(this.options.validators){
            for(const validator of this.options.validators){
                const isValid = await validator.isValid(value)
                // if(!isValid){
                //     throw new BadRequestException(`Validation failed (${validator} is not a valid enum`)
                // }
            }
        }
        return value;
    }
}
